package com.rock.upms.client.controller;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.rock.common.base.BaseController;
import com.rock.common.base.BaseResult;
import com.rock.common.util.ByteUtil;
import com.rock.common.util.RedisUtil;
import com.rock.common.util.SerializeUtil;
import com.rock.upms.client.config.Global;
import io.swagger.annotations.Api;

/**
 * 
 * @Description:TODO  
 * @author: hotdog  
 * @date:   2018年7月30日 下午10:06:21     
 * @Copyright: v1.0 
 *
 */
@Controller
@Api(value = "第三方登录验证")
public class ThirdLogin extends BaseController {

	private static final Logger log = LoggerFactory.getLogger(IndexController.class);

	//url:127.0.0.1:6060/upms/a/thirdLogin?usercode=03353004&
	// 获取系统ID对应的菜单列表
	@ResponseBody
	@RequestMapping(value = "${adminPath}/validateLogin", method = RequestMethod.GET)
	public BaseResult validateLogin() {
		Subject subject = SecurityUtils.getSubject();
		Session session = subject.getSession();
		String sessionId = session.getId().toString();
		// 判断是否已登录，如果已登录，则回跳，防止重复登录
		byte[] tokenCodeByte = RedisUtil.hget(ByteUtil.getByteKey(Global.SSO_SERVER_SESSIONID, sessionId), "token".getBytes());
		String tokenCode = "";
		if (tokenCodeByte != null) {
			tokenCode = (String) SerializeUtil.deserialize(tokenCodeByte);
		}
		// token校验值
		if (StringUtils.isBlank(tokenCode)) {
			return BaseResult.fail("登录失败");
		}
		return BaseResult.success("");
	
	}
}